(function(angular) {
	'use strict';
	angular.module('fs.waf').controller('cda.apTradepartner.viewController', viewController);
	viewController.$inject = [ '$scope', 'Constants', 'layoutConfig', 'validatorConfig', 'gridService', 'authService', 'apTradepartnerService', '$filter' ];
	function viewController($scope, Constants, layoutConfig, validatorConfig, gridService, authService, apTradepartnerService, $filter) {
		var ctrl = this, apTradepartnerInfo = $scope.$stateParams.params;
		//ctrl.layoutConfig = layoutConfig;
		ctrl.validatorConfig = validatorConfig;
		ctrl.apTradepartner = {};

		ctrl.init = function() {
			var params = {
					tradepartnerId : apTradepartnerInfo.tradepartnerId
			};
			// init acct
			apTradepartnerService.initProfAcct(layoutConfig, $scope, ctrl);
			// init int
			//apTradepartnerService.initProfInt(layoutConfig, $scope, ctrl);
			//apTradepartnerService.initProfCostOfFundInt(layoutConfig, $scope, ctrl);
			// init pastdue
			apTradepartnerService.initProfPastdue(layoutConfig, $scope, ctrl);
			// init fee
			apTradepartnerService.initProfFee(layoutConfig, $scope, ctrl);
			// init doc
			apTradepartnerService.initEventDoccfg(layoutConfig, $scope, ctrl);
			// init limit facility
			//apTradepartnerService.initProfLimitFaci(layoutConfig, $scope, ctrl);
			//apTradepartnerService.initProfLimitInsFaci(layoutConfig, $scope, ctrl);
			//apTradepartnerService.initProfLimitPurFaci(layoutConfig, $scope, ctrl);
			// init Settlement Instruction
			apTradepartnerService.initProfSetlinst(layoutConfig, $scope, ctrl);
			// init cust prop define
			apTradepartnerService.initCustProp(layoutConfig, $scope, ctrl);
			//
			apTradepartnerService.initGeneral($scope, ctrl).then(function() {
				authService.view(params).then(function(response) {
					var initApTradepartner = response.data || apTradepartnerInfo;
					ctrl.action = "view";
					apTradepartnerService.initLayoutConfigAndModel($scope, ctrl, initApTradepartner, ctrl.action, false).then(function() {
					});
				});
			});
		};
		
	}
})(angular);